#!/bin/bash

# 网站脚本前面必须这样写
echo "Content-Type:text/html; charset=utf-8"
echo ""

echo "<h1 color="#FF0000">觉行教育</h1>"
echo "<img src="/jx.png" /></br>"
echo "<a href="/cgi-bin/listClass.sh">班级列表</a>"
echo "<a href="/cgi-bin/listStu.sh">学生列表</a>"
echo "<a href="/cgi-bin/listTest.sh">考试列表</a>"
echo "<a href="/cgi-bin/listSubject.sh">科目列表</a>"
echo "<a href="/cgi-bin/listScore.sh">成绩列表</a>"
echo "<a href="/addStu.html">添加学生</a>"
echo "<a href="/addScore.html">添加成绩</a>"

echo '
<style type="text/css">
table {
	width: 15%;
	background: #ccc;
	margin: 10px left;
	border-collapse: collapse;
}
th,
td {
	height: 25px;
	line-height: 25px;
	text-align: center;
	border: 1px solid #ccc;
}
th {
	background: #eee;
	font-weight: normal;
}
tr {
	background: #fff;
}
tr:hover {
	background: #cc0;
}
td a {
	color: #06f;
	text-decoration: none;
}
td a:hover {
	color: #06f;
	text-decoration: underline;
}
</style>
'


dbaddr="127.0.0.1"
dbuser="root"
dbpasswd="123456"
mysqlexec="mysql --default-character-set=utf8 -h$dbaddr -u$dbuser -p$dbpasswd jx -e "

function listTable() {
  idList=$($mysqlexec "select id from $1" | grep -v id)
  
  for id in ${idList[@]}; do
    echo "<tr>"
    fieldList=$($mysqlexec "select *from $1 where id=$id" | grep -v id)
    for field in ${fieldList[@]}; do
      echo "<td>$field</td>"
    done
    echo "</tr>"
  done
  echo "</table>"
}
